import os.path

from flask import Flask, request, render_template

app = Flask(__name__)

upload_dir = "upload_files"


@app.route('/')
def upload_file():
    return render_template('upload_file.html')


@app.route('/upload_api', methods=['POST'])
def upload_api():
    base_dir = os.path.dirname(os.path.abspath(__file__))
    target_dir = os.path.join(base_dir, upload_dir)
    if not os.path.exists(target_dir):
        os.makedirs(target_dir)
    file = request.files['file']
    target_file = os.path.join(target_dir, file.filename)
    file.save(target_file)
    return '文件上传成功！'


if __name__ == '__main__':
    app.run(host="0.0.0.0",port=18888)
